//
//  SelcetCityViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/17.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "SelcetCityViewController.h"
#import "LYSelectCityView.h"

@interface SelcetCityViewController ()
@property (nonatomic, strong) LYSelectCityView *cityView;
@end

@implementation SelcetCityViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI {
    self.view.backgroundColor = COLOR_OF_WHITE;
    
    self.navigationItem.title = @"城市";
    
    NSURL *URL = [[NSBundle mainBundle] URLForResource:@"city" withExtension:@"plist"];
    NSArray *cityArray=[NSArray arrayWithContentsOfURL:URL];
    
    UIButton *okBtn = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH-50*Scale, HeightOfStatusBar+3*Scale, 50*Scale, 36*Scale) imageName:nil target:self action:@selector(okBtnTap) title:@"确定" titleColor:THEMECOLOR_OF_ORANGE];
    okBtn.titleLabel.font = Font(Font_15);
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:okBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    self.cityView = [[LYSelectCityView alloc] initCityData:cityArray CityState:CityStateSecondary];
    [self.view addSubview:self.cityView];
}

- (void)okBtnTap {
//    NSDictionary *dic = [self.cityView getAllCityInfo];
    
//    NSString *str = [NSString stringWithFormat:@"%@%@-%@%@-%@%@", dic[@"province"], dic[@"provinceid"], dic[@"city"], dic[@"cityid"], dic[@"area"], dic[@"areaid"]];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(selcetCityViewControllerInfo:)]) {
        NSDictionary *dic = [self.cityView getAllCityInfo];
        [self.delegate selcetCityViewControllerInfo:dic];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

@end
